/**
 *  编辑页
 *
 * 作者 admin
 * 日期 2024-08-07 16:43:01
 */
layui.use(['jquery','febs', 'form', 'validate','fileUpload'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        laydate = layui.laydate,
        form = layui.form,
        fileUpload = layui.fileUpload,
        $view = $('#reportBaseInfo-edit'),
        $accidentType = $('div[name="accidentType"]'),
        $accidentLevel = $('div[name="accidentLevel"]'),
        $accidentShipType = $('div[name="accidentShipType"]'),
        validate = layui.validate;
    let accidentReportFileList = [];

    initDictItemLabel_reportBaseInfo();
    form.verify(validate);
    form.render();
    initFormValue();

    laydate.render({
        elem: "#accidentDate",
        done: function (value, date) {},
        type: 'datetime'
    })

    laydate.render({
        elem: "#rectifyDeadLine",
        done: function (value, date) {},
        type: 'date'
    })

    laydate.render({
        elem: "#noticeDeptDate",
        done: function (value, date) {},
    })

    function initDictItemLabel_reportBaseInfo(){
        febs.initDictItemLabel($accidentType,'SAFETY_ACCIDENT_TYPE',accidentReportData.accidentType);
        febs.initDictItemLabel($accidentLevel,'SAFETY_ACCIDENT_LEVEL',accidentReportData.accidentLevel);
        febs.initDictItemLabel($accidentShipType,'SAFETY_SHIP_TYPE',accidentReportData.accidentShipType);
    }
    function initFormValue() {
        if (accidentReportData) {
            //事故上报附件
            accidentReportFileList = accidentReportData.accidentReportFileList;
            if(accidentReportFileList && accidentReportFileList.length>0){
                renderFile('#uploadReportBtn',accidentReportFileList);
            }
            form.val("reportBaseInfo-edit-form", {
                "reportId": accidentReportData.reportId,
                "tenantId": accidentReportData.tenantId,
                "accidentNo": accidentReportData.accidentNo,
                "accidentType": accidentReportData.accidentType,
                "accidentTitle": accidentReportData.accidentTitle,
                "accidentDate": accidentReportData.accidentDate,
                "accidentAreaId": accidentReportData.accidentAreaId,
                "accidentAreaName": accidentReportData.accidentAreaName,
                "accidentLevel": accidentReportData.accidentLevel,
                "accidentReason": accidentReportData.accidentReason,
                "noticeDeptFlg": accidentReportData.noticeDeptFlg,
                "noticeDeptName": accidentReportData.noticeDeptName,
                "noticeDeptDate": accidentReportData.noticeDeptDate,
                "preliminarilyDamage": accidentReportData.preliminarilyDamage,
                "preliminarilyDescript": accidentReportData.preliminarilyDescript,
                "status": accidentReportData.status,
            });
            if(accidentReportData.noticeDeptFlg === '1'){
                $("#noticeDeptDiv").show();
            }else{
                $("#noticeDeptDiv").hide();
            }
            form.render('checkbox');
        }
    }
    function renderFile(elem,fileList){
        fileUpload.render({
            elem:elem,
            url:ctx + 'accident/upload',
            type:'2',
            maxNum:5,
            isDetail:true,
            defaultData: fileList,
            done:function(res){
            }
            ,error: function(){
                layer.msg("服务器异常")
            }
        })
    }

});